//
//  MessageTransmit.m
//  OCTest
//
//  Created by 韩艳锋 on 2018/4/27.
//  Copyright © 2018年 韩艳锋. All rights reserved.
//

#import "MessageTransmit.h"
#import <objc/runtime.h>
#import "MessageTransmitOther.h"

@implementation MessageTransmit

+ (BOOL)resolveInstanceMethod:(SEL)sel{
    
//    Class cl = [self class];
//    return class_addMethod(cl, sel, message, "v@:@");
    NSLog(@"1");
    return NO;
}

void message(id self, SEL _cmd, NSString * message) {
    NSLog(@"%@", message);
};


- (id)forwardingTargetForSelector:(SEL)aSelector {
//    return [[MessageTransmitOther alloc] init];
    NSLog(@"2");
    return nil;
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
    NSString * sel = NSStringFromSelector(aSelector);
    if ([sel isEqualToString:@"sendInstantMessage:"]) {
        return [NSMethodSignature signatureWithObjCTypes:"v@:@"];
    }
    return [super methodSignatureForSelector:aSelector];
}

- (void)forwardInvocation:(NSInvocation *)anInvocation {
    SEL selector = [anInvocation selector];
    MessageTransmitOther * ss = [[MessageTransmitOther alloc] init];
    if ([ss respondsToSelector:selector]) {
        [anInvocation invokeWithTarget:ss];
    }
}
@end
